package com.org.gundutubruk;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

public class OpeningAnimation extends Activity {
    /** Atribut */
	AnimationDrawable openingAnimation;
	LinearLayout openingImage;
	static Thread t;
	boolean isRunning;
	/** Saat pembuatan Activity baru */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.opening_animasi_layout);		
        openingImage=(LinearLayout)findViewById(R.id.opening);
        openingImage.setBackgroundResource(R.drawable.opening_animasi);
        Log.d("dd", ""+openingImage.getBackground());
        openingAnimation=(AnimationDrawable)openingImage.getBackground();
        isRunning=true;
        t = new Thread(){
        	public void run(){
        		try {
        			int i=1;
        			while(isRunning&&i<18){
        				i++;
        				sleep(1000);
        			}
        			nextAct();
        		} catch (InterruptedException e) {
					e.printStackTrace();
				}
        	}
        };
        t.start();
    }
    
    /** Animasi jalan saat masuk ke activity ini */
    public void onWindowFocusChanged (boolean hasFocus){
    	openingAnimation.start();
    }
    
    /** Mendeteksi saat layar disentuh untuk melanjutkan ke activity berikutnya */
    public boolean onTouchEvent(MotionEvent evt){
		isRunning=false;
		return true;
    }
    
    /** Membuat activity baru*/
	public void nextAct(){
		this.startActivity(new Intent("android.intent.action.MENUUTAMA"));
		overridePendingTransition(R.anim.fade, R.anim.hold);
		this.finish();
		
	}
}